<?php
/**
 * Created by PhpStorm.
 * User: zyw
 * Date: 2018-02-25
 * Time: 16:50
 */
class Index extends MY_Controller {

    public function __construct(){
        parent::__construct();
    }
    public function index()
    {
        $pageTitle = "暖光后台";
        $this->load->view('index/index', array(
            'pageTitle' => $pageTitle,
        ));
    }
    public function index_data()
    {
        $pageTitle = "首页";
        $endTime = time();
        $startTime = strtotime("-7 days");
        //主贴数据
        $postDayList = $this->IndexModel->tongjiPostDay($startTime, $endTime);
        //评论数据
        $replyDayList = $this->IndexModel->tongjiReplyDay($startTime, $endTime);

        $this->load->view('index/index_data', array(
            'pageTitle' =>$pageTitle,
            "postDayList" => $postDayList,
            "replyDayList" => $replyDayList,
        ));
    }
    public function post_list_data(){
        $add_time = $this->input->get_post('add_time') ? $this->input->get_post('add_time') : "-7";
        $endTime = time();
        $startTime = strtotime($add_time." days");
        //主贴数据
        $postDayList = $this->IndexModel->tongjiPostDay($startTime, $endTime);

        $j_addNumTotal = 0;$j_auditNumTotal=0;$j_tongNumTotal=0;$j_weiNumTotal=0;$j_delNumTotal=0;$j_hotNumTotal=0;
        $z_addNumTotal = 0;$z_auditNumTotal=0;$z_tongNumTotal=0;$z_weiNumTotal=0;$z_delNumTotal=0;$z_hotNumTotal=0;

        $html = "";
        foreach($postDayList as $postDay){
            $startTime = strtotime($postDay["add_time"]." 00:00:00");
            $endTime = strtotime($postDay["add_time"]." 23:59:59");

            $j_addParam = array("startTime"=>$startTime, "endTime"=>$endTime, "source_type"=>1);
            $j_addNum = $this->IndexModel->tongjiPostNum($j_addParam);
            $j_addNumTotal += $j_addNum;

            $z_addParam = array("startTime"=>$startTime, "endTime"=>$endTime, "source_type"=>2);
            $z_addNum = $this->IndexModel->tongjiPostNum($z_addParam);
            $z_addNumTotal += $z_addNum;

            $j_auditParam  = array("startTime"=>$startTime, "endTime"=>$endTime, "is_audit" => 1, "source_type"=>1);
            $j_auditNum  = $this->IndexModel->tongjiPostNum($j_auditParam);
            $j_auditNumTotal+=$j_auditNum;

            $z_auditParam  = array("startTime"=>$startTime, "endTime"=>$endTime, "is_audit" => 1, "source_type"=>2);
            $z_auditNum  = $this->IndexModel->tongjiPostNum($z_auditParam);
            $z_auditNumTotal+=$z_auditNum;

            $j_tongParam  = array("startTime"=>$startTime, "endTime"=>$endTime, "is_audit" => 1, "status" => 1, "source_type"=>1);
            $j_tongNum = $this->IndexModel->tongjiPostNum($j_tongParam);
            $j_tongNumTotal+=$j_tongNum;

            $z_tongParam  = array("startTime"=>$startTime, "endTime"=>$endTime, "is_audit" => 1, "status" => 1, "source_type"=>2);
            $z_tongNum = $this->IndexModel->tongjiPostNum($z_tongParam);
            $z_tongNumTotal+=$z_tongNum;

            $j_weiParam  = array("startTime"=>$startTime, "endTime"=>$endTime, "is_audit" => 1, "status" => 2, "source_type"=>1);
            $j_weiNum  = $this->IndexModel->tongjiPostNum($j_weiParam);
            $j_weiNumTotal+=$j_weiNum;

            $z_weiParam  = array("startTime"=>$startTime, "endTime"=>$endTime, "is_audit" => 1, "status" => 2, "source_type"=>2);
            $z_weiNum  = $this->IndexModel->tongjiPostNum($z_weiParam);
            $z_weiNumTotal+=$z_weiNum;

            $j_delParam = array("startTime"=>$startTime, "endTime"=>$endTime, "is_audit" => 1, "status" => 3, "source_type"=>1);
            $j_delNum  = $this->IndexModel->tongjiPostNum($j_delParam);
            $j_delNumTotal+=$j_delNum;

            $z_delParam = array("startTime"=>$startTime, "endTime"=>$endTime, "is_audit" => 1, "status" => 3, "source_type"=>2);
            $z_delNum  = $this->IndexModel->tongjiPostNum($z_delParam);
            $z_delNumTotal+=$z_delNum;

            $j_hotParam = array("startTime"=>$startTime, "endTime"=>$endTime, "is_hot" => 1, "status" => 1, "source_type"=>1);
            $j_hotNum  = $this->IndexModel->tongjiPostNum($j_hotParam);
            $j_hotNumTotal+=$j_hotNum;

            $z_hotParam = array("startTime"=>$startTime, "endTime"=>$endTime, "is_hot" => 1, "status" => 1, "source_type"=>2);
            $z_hotNum  = $this->IndexModel->tongjiPostNum($z_hotParam);
            $z_hotNumTotal+=$z_hotNum;

            $html.='<tr>';
            $html.='    <td>'.$postDay["add_time"].'</td>';
            $html.='    <td>机器：'.$j_addNum.';注册:'.$z_addNum.'</td>';
            $html.='    <td>机器：'.$j_auditNum.';注册:'.$z_auditNum.'</td>';
            $html.='    <td>机器：'.$j_tongNum.';注册:'.$z_tongNum.'</td>';
            $html.='    <td>机器：'.$j_weiNum.';注册:'.$z_weiNum.'</td>';
            $html.='    <td>机器：'.$j_delNum.';注册:'.$z_delNum.'</td>';
            $html.='    <td>机器：'.$j_hotNum.';注册:'.$z_delNum.'</td>';
            $j_a = ($j_addNum > 0 ? round($j_hotNum / $j_addNum * 100,2) : 0)."%";
            $z_a = ($z_addNum > 0 ? round($z_hotNum / $z_addNum * 100,2) : 0)."%";
            $j_d = ($j_addNum > 0 ? round(($j_delNum + $j_weiNum) / $j_addNum * 100,2) : 0)."%";
            $z_d = ($z_addNum > 0 ? round(($z_delNum + $z_weiNum) / $z_addNum * 100,2) : 0)."%";
            $html.='    <td>机器：'.$j_a.';注册:'.$z_a.'</td>';
            $html.='    <td>机器：'.$j_d.';注册:'.$z_d.'</td>';
            $html.='</tr>';
        }
        $html.='<tr>';
        $html.='    <td>合计</td>';
        $html.='    <td>机器：'.$j_addNumTotal.';注册:'.$z_addNumTotal.'</td>';
        $html.='    <td>机器：'.$j_auditNumTotal.';注册:'.$z_auditNumTotal.'</td>';
        $html.='    <td>机器：'.$j_tongNumTotal.';注册:'.$z_tongNumTotal.'</td>';
        $html.='    <td>机器：'.$j_weiNumTotal.';注册:'.$z_weiNumTotal.'</td>';
        $html.='    <td>机器：'.$j_delNumTotal.';注册:'.$z_delNumTotal.'</td>';
        $html.='    <td>机器：'.$j_hotNumTotal.';注册:'.$z_hotNumTotal.'</td>';
        $j_a = ($j_addNumTotal > 0 ? round($j_hotNumTotal / $j_addNumTotal * 100,2) : 0)."%";
        $z_a = ($z_addNumTotal > 0 ? round($z_hotNumTotal / $z_addNumTotal * 100,2) : 0)."%";
        $j_d = ($j_addNumTotal > 0 ? round(($j_delNumTotal + $j_weiNumTotal) / $j_addNumTotal * 100,2) : 0)."%";
        $z_d = ($z_addNumTotal > 0 ? round(($z_delNumTotal + $z_weiNumTotal) / $z_addNumTotal * 100,2) : 0)."%";
        $html.='    <td>机器：'.$j_a.';注册:'.$z_a.'</td>';
        $html.='    <td>机器：'.$j_d.';注册:'.$z_d.'</td>';
        $html.='</tr>';
        std_out(0,"", $html);
    }

    public function rely_list_data(){
        $add_time = $this->input->get_post('add_time') ? $this->input->get_post('add_time') : "-7";
        $endTime = time();
        $startTime = strtotime($add_time." days");
        //主贴数据
        $postDayList = $this->IndexModel->tongjiReplyDay($startTime, $endTime);

        $j_addNumTotal = 0;$j_auditNumTotal=0;$j_tongNumTotal=0;$j_weiNumTotal=0;$j_delNumTotal=0;
        $z_addNumTotal = 0;$z_auditNumTotal=0;$z_tongNumTotal=0;$z_weiNumTotal=0;$z_delNumTotal=0;
        $html = "";
        foreach($postDayList as $postDay){
            $startTime = strtotime($postDay["add_time"]." 00:00:00");
            $endTime = strtotime($postDay["add_time"]." 23:59:59");

            $j_addParam = array("startTime"=>$startTime, "endTime"=>$endTime, "source_type"=>1);
            $j_addNum = $this->IndexModel->tongjiReplyNum($j_addParam);
            $j_addNumTotal += $j_addNum;

            $z_addParam = array("startTime"=>$startTime, "endTime"=>$endTime, "source_type"=>2);
            $z_addNum = $this->IndexModel->tongjiReplyNum($z_addParam);
            $z_addNumTotal += $z_addNum;

            $j_auditParam  = array("startTime"=>$startTime, "endTime"=>$endTime, "is_audit" => 1, "source_type"=>1);
            $j_auditNum  = $this->IndexModel->tongjiReplyNum($j_auditParam);
            $j_auditNumTotal+=$j_auditNum;

            $z_auditParam  = array("startTime"=>$startTime, "endTime"=>$endTime, "is_audit" => 1, "source_type"=>2);
            $z_auditNum  = $this->IndexModel->tongjiReplyNum($z_auditParam);
            $z_auditNumTotal+=$z_auditNum;

            $j_tongParam  = array("startTime"=>$startTime, "endTime"=>$endTime, "is_audit" => 1, "status" => 1, "source_type"=>1);
            $j_tongNum = $this->IndexModel->tongjiReplyNum($j_tongParam);
            $j_tongNumTotal+=$j_tongNum;

            $z_tongParam  = array("startTime"=>$startTime, "endTime"=>$endTime, "is_audit" => 1, "status" => 1, "source_type"=>2);
            $z_tongNum = $this->IndexModel->tongjiReplyNum($z_tongParam);
            $z_tongNumTotal+=$z_tongNum;

            $j_weiParam  = array("startTime"=>$startTime, "endTime"=>$endTime, "is_audit" => 1, "status" => 2, "source_type"=>1);
            $j_weiNum  = $this->IndexModel->tongjiReplyNum($j_weiParam);
            $j_weiNumTotal+=$j_weiNum;

            $z_weiParam  = array("startTime"=>$startTime, "endTime"=>$endTime, "is_audit" => 1, "status" => 2, "source_type"=>2);
            $z_weiNum  = $this->IndexModel->tongjiReplyNum($z_weiParam);
            $z_weiNumTotal+=$z_weiNum;

            $j_delParam = array("startTime"=>$startTime, "endTime"=>$endTime, "is_audit" => 1, "status" => 3, "source_type"=>1);
            $j_delNum  = $this->IndexModel->tongjiReplyNum($j_delParam);
            $j_delNumTotal+=$j_delNum;

            $z_delParam = array("startTime"=>$startTime, "endTime"=>$endTime, "is_audit" => 1, "status" => 3, "source_type"=>2);
            $z_delNum  = $this->IndexModel->tongjiReplyNum($z_delParam);
            $z_delNumTotal+=$z_delNum;

            $html.='<tr>';
            $html.='    <td>'.$postDay["add_time"].'</td>';
            $html.='    <td>机器：'.$j_addNum.';注册:'.$z_addNum.'</td>';
            $html.='    <td>机器：'.$j_auditNum.';注册:'.$z_auditNum.'</td>';
            $html.='    <td>机器：'.$j_tongNum.';注册:'.$z_tongNum.'</td>';
            $html.='    <td>机器：'.$j_weiNum.';注册:'.$z_weiNum.'</td>';
            $html.='    <td>机器：'.$j_delNum.';注册:'.$z_delNum.'</td>';
            $j_a = ($j_addNum > 0 ? round(($j_delNum + $j_weiNum) / $j_addNum * 100,2) : 0)."%";
            $z_a = ($z_addNum > 0 ? round(($z_delNum + $z_weiNum) / $z_addNum * 100,2) : 0)."%";
            $html.='    <td>机器：'.$j_a.';注册:'.$z_a.'</td>';
            $html.='</tr>';
        }
        $html.='<tr>';
        $html.='    <td>合计</td>';
        $html.='    <td>机器：'.$j_addNumTotal.';注册:'.$z_addNumTotal.'</td>';
        $html.='    <td>机器：'.$j_auditNumTotal.';注册:'.$z_auditNumTotal.'</td>';
        $html.='    <td>机器：'.$j_tongNumTotal.';注册:'.$z_tongNumTotal.'</td>';
        $html.='    <td>机器：'.$j_weiNumTotal.';注册:'.$z_weiNumTotal.'</td>';
        $html.='    <td>机器：'.$j_delNumTotal.';注册:'.$z_delNumTotal.'</td>';
        $j_a = ($j_addNumTotal > 0 ? round(($j_delNumTotal + $j_weiNumTotal) / $j_addNumTotal * 100,2) : 0)."%";
        $z_a = ($z_addNumTotal > 0 ? round(($z_delNumTotal + $z_weiNumTotal) / $z_addNumTotal * 100,2) : 0)."%";
        $html.='    <td>机器：'.$j_a.';注册:'.$z_a.'</td>';
        $html.='</tr>';
        std_out(0,"", $html);
    }

    public function user_list_data(){
        $add_time = $this->input->get_post('add_time') ? $this->input->get_post('add_time') : "-7";

        $j_addNumTotal = 0;$j_loginNumTotal=0;$j_postNumTotal=0;$j_replyNumTotal=0;$j_likeNumTotal=0;$j_shareNumTotal=0;
        $z_addNumTotal = 0;$z_loginNumTotal=0;$z_postNumTotal=0;$z_replyNumTotal=0;$z_likeNumTotal=0;$z_shareNumTotal=0;
        $html = "";
        for($i = 0 ; $i >= $add_time; $i--){
            $time = strtotime($i." days", time());
            $day = date("Y-m-d", $time);
            $startTime = strtotime($day." 00:00:00");
            $endTime = strtotime($day." 23:59:59");

            $j_addNum = $this->IndexModel->tongjiUserNum($startTime, $endTime, 1, 1);
            $j_addNumTotal += $j_addNum;

            $z_addNum = $this->IndexModel->tongjiUserNum($startTime, $endTime, 1, 2);
            $z_addNumTotal += $z_addNum;

            $j_loginNum  = $this->IndexModel->tongjiUserNum($startTime, $endTime, 2, 1);
            $j_loginNumTotal+=$j_loginNum;

            $z_loginNum  = $this->IndexModel->tongjiUserNum($startTime, $endTime, 2, 2);
            $z_loginNumTotal+=$z_loginNum;

            $j_postNum = $this->IndexModel->tongjiUserNum($startTime, $endTime, 3, 1);
            $j_postNumTotal+=$j_postNum;

            $z_postNum = $this->IndexModel->tongjiUserNum($startTime, $endTime, 3, 2);
            $z_postNumTotal+=$z_postNum;

            $j_replyNum  = $this->IndexModel->tongjiUserNum($startTime, $endTime, 4, 1);
            $j_replyNumTotal+=$j_replyNum;

            $z_replyNum  = $this->IndexModel->tongjiUserNum($startTime, $endTime, 4, 2);
            $z_replyNumTotal+=$z_replyNum;

            $j_likeNum  = $this->IndexModel->tongjiUserNum($startTime, $endTime, 5, 1);
            $j_likeNumTotal+=$j_likeNum;

            $z_likeNum  = $this->IndexModel->tongjiUserNum($startTime, $endTime, 5, 2);
            $z_likeNumTotal+=$z_likeNum;

            $j_shareNum  = $this->IndexModel->tongjiUserNum($startTime, $endTime, 6, 1);
            $j_shareNumTotal+=$j_shareNum;

            $z_shareNum  = $this->IndexModel->tongjiUserNum($startTime, $endTime, 6, 2);
            $z_shareNumTotal+=$z_shareNum;

            $html.='<tr>';
            $html.='    <td>'.$day.'</td>';
            $html.='    <td>机器：'.$j_addNum.';注册:'.$z_addNum.'</td>';
            $html.='    <td>机器：'.$j_loginNum.';注册:'.$z_loginNum.'</td>';
            $html.='    <td>机器：'.$j_postNum.';注册:'.$z_postNum.'</td>';
            $html.='    <td>机器：'.$j_replyNum.';注册:'.$z_replyNum.'</td>';
            $html.='    <td>机器：'.$j_likeNum.';注册:'.$z_likeNum.'</td>';
            $html.='    <td>机器：'.$j_shareNum.';注册:'.$z_shareNum.'</td>';
            $html.='</tr>';
        }
        $html.='<tr>';
        $html.='    <td>合计</td>';
        $html.='    <td>机器：'.$j_addNumTotal.';注册:'.$z_addNumTotal.'</td>';
        $html.='    <td>机器：'.$j_loginNumTotal.';注册:'.$z_loginNumTotal.'</td>';
        $html.='    <td>机器：'.$j_postNumTotal.';注册:'.$z_postNumTotal.'</td>';
        $html.='    <td>机器：'.$j_replyNumTotal.';注册:'.$z_replyNumTotal.'</td>';
        $html.='    <td>机器：'.$j_likeNumTotal.';注册:'.$z_likeNumTotal.'</td>';
        $html.='    <td>机器：'.$j_shareNumTotal.';注册:'.$z_shareNumTotal.'</td>';
        $html.='</tr>';
        std_out(0,"", $html);
    }

}
